/**
 * Minimal gthread environment on Monarc 
 */

/*
   Copyright 2006 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef GTHR_MONARC_H
#define GTHR_MONARC_H

#define __GTHREADS 1
#include <mutex.h>

typedef mutex_t __gthread_mutex_t;
typedef struct
{
  mutex_t mutex;
  int once;
} __gthread_once_t;

typedef unsigned int __gthread_key_t;

#define __GTHREAD_MUTEX_INIT MUTEX_UNLOCKED
#define __GTHREAD_ONCE_INIT { MUTEX_UNLOCKED, 0 }
/**
 * our thread system is active
 */
#ifdef __cplusplus
extern "C" {
#endif

int __gthread_active_p();

int __gthread_mutex_lock (__gthread_mutex_t *mutex);

int __gthread_mutex_trylock (__gthread_mutex_t *mutex);

int __gthread_mutex_unlock (__gthread_mutex_t *mutex);

void * __gthread_getspecific (__gthread_key_t key);

int __gthread_setspecific (__gthread_key_t key, void * data);

int __gthread_key_create(__gthread_key_t *key, void (*destructor)(void *));

int __gthread_key_delete (__gthread_key_t key);

int __gthread_key_dtor (__gthread_key_t key, void *ptr);

int __gthread_once (__gthread_once_t *once, void (*func) ());

#ifdef __cplusplus
}
#endif

#endif

